<template>
  <div class="panel-container">
    <div class="panel-content">
      <div class="panel-title">{{ title }}</div>
      <div class="funnel-list">
        <div class="item" v-for="(item, index) in dataList" :key="item.name" :class="{ animation: animation }">
          <div class="text">
            <div class="name">{{ item.name }}</div>
            <div class="value">{{ item.value }}</div>
          </div>
          <div class="percent" v-if="index > 0">{{ percent(item.value, dataList[index - 1].value) }}%</div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { apiDuxAi } from '@/api/dataStatistics'

export default {
  name: 'Panel3',
  props: {
    title: String,
    time: Object,
  },
  watch: {
    time: function () {
      this.getData()
    },
  },
  data() {
    return {
      animation: true,
      dataList: {},
    }
  },
  mounted() {},
  destroyed() {},
  activated() {},
  methods: {
    getData() {
      apiDuxAi(this.time).then((res) => {
        this.animation = false
        this.dataList = res.info.data
        setTimeout(() => {
          this.animation = true
        }, 100)
      })
    },
    // 百分数
    percent(a, b) {
      if (a === 0 || b === 0) {
        return 0
      } else {
        return ((a / b) * 100).toFixed(2)
      }
    },
  },
}
</script>

<style scoped lang="scss">
.panel-line {
  align-items: flex-start;
}

.panel-content {
  margin-bottom: 20px;
  &:last-child {
    margin-bottom: 0;
  }
}
.funnel-list {
  width: 100%;
  height: 400px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: 10px;
  .item {
    width: 100%;
    position: relative;
    height: 8vh;
    margin-bottom: 4px;
    opacity: 0.8;
    &:hover {
      opacity: 1;
    }
    .text {
      text-align: center;
      position: absolute;
      padding-top: 2vh;
      color: transparent;
      .name {
        margin-bottom: 6px;
      }
    }
    .percent {
      position: relative;
      color: #999999;
      width: 100%;
      text-align: right;
      padding-right: 10px;
      top: -8px;
      &::before {
        content: '';
        position: absolute;
        right: 50px;
        top: 5px;
        width: 40%;
        height: 1px;
        background: #999999;
      }
    }

    &.animation {
      .text {
        color: #ffffff;
        transition: 2s;
      }
      &::before {
        transition: 0.5s;
        border: 8vh solid transparent;
        border-left-width: 15px;
        border-right-width: 15px;
        border-top-color: #5db42c;
      }
    }
    &::before {
      content: '';
      position: absolute;
      height: 0;
      border: 0vh solid transparent;
      border-left-width: 15px;
      border-right-width: 15px;
      border-top-color: #5db42c;
    }
    &:nth-child(1) {
      .text {
        width: 50%;
      }
      &::before {
        width: 50%;
        left: 0;
      }
    }
    &:nth-child(2) {
      .text {
        width: calc(50% - 30px);
        left: 15px;
      }
      &::before {
        width: calc(50% - 30px);
        left: 15px;
        border-top-color: #f08200;
      }
      .percent {
        padding-right: 20px;
        &::before {
          right: 65px;
        }
      }
    }
    &:nth-child(3) {
      .text {
        width: calc(50% - 60px);
        left: 30px;
      }
      &::before {
        width: calc(50% - 60px);
        left: 30px;
        border-top-color: #2b71b8;
      }
      .percent {
        padding-right: 35px;
        &::before {
          right: 80px;
        }
      }
    }
    &:nth-child(4) {
      .text {
        width: calc(50% - 90px);
        left: 45px;
      }
      &::before {
        width: calc(50% - 90px);
        left: 45px;
        border-top-color: #f56c6c;
      }
      .percent {
        padding-right: 50px;
        &::before {
          right: 95px;
        }
      }
    }
  }
}
</style>
